The instructions below assume that you've already compiled emc2 on your system; Instructions on compiling the latest testing release can be found at Testing. The instructions also assume that you know something about LadderProgramming.
This page is quite dated but the ideas are basically the same (Feb 08)
Now you can test this same system using ClassicLadder as modified for emc. The command for this is
scripts/emc configs/demo_step_cl/demo_step_cl.ini
The demo_step_cl files start up the EMC, HAL, and ClassicLadder. They also start up the display part of ladder so that you can edit the machine logic to suit your machine. These displays include the ladder editor, signal display, and ladder. This starts an overwhelming pile of widgets on the screen. I've hidden a couple of the screens and moved others around so that you can see the essential stuff in the picture below
This section begins to detail the operation of ladder. Connections are only briefly defined here. The way that these are setup are listed in detail in the HAL section. The list of input and output signals are:
If you are anything like me, these names will help some but you will be confused about how they work as you study the sample ladder images. Hang in there and the details should come clear after some study.
Look at the ladder on the right and decide what the operator must do to enable the EMC? Answer backwards is teser-potse ro <1F> sserp dna nottub lanretxe eht esaeler. |
A quick look at the intermittent lube system setup in the second rung of demo_step_cl.clp.
T0 and T1 are set up to toggle. As soon as the EMC sees machine on it asks for lube so the I3 contact closes sending a signal through B0 to T0. As soon as T0 gets power it begins to count down and it turns on the R signal out. That output turns on Q1 which is connected to a parport pin that turns on the lube pump. The details of these hardware connections are described in the HAL section below.
You'll notice that the R and D outputs from T0 are connected to set and reset Q1. This way we are able to avoid any interaction between rungs. If we used an ordinary ladder coil, it might switch on and off several times before it settled down and started working properly. This coil is the ladder equivalent of a debounce thing or a latching coil.
When T0 reaches the end of it's count, it turns off Q1. This stops the lube pump and closes the NC contact on the next row. This causes T1 to begin counting and pulls its R output low. This energizes the internal ClassicLadder coil B0 and opens the NC contact to T0. This resets T0 to it's count so that when T1 times out, the lube pump will come on again. Once you get the hang of reading ladder it is easier to see the logic there than to read it here.
There is one other thing that happens when EMC turns the machine on. Power is supplied through the normally open, but now closed, I4 and begins a countdown on T2. If I4 does not open in 9.9 minutes, Q2 will turn off and that will notify the EMC that there is a problem with lubrication on the machine. I designed my lube system with a little pressure switch on the output of the pump. Once the lube pump has run for a few seconds, this sensor opens and resets T2. This keeps happening until the lube pump runs out of oil or it's motor dies. Once that happens and T2 times out, the error message is returned to EMC.
The ladder display widgets leave something to be desired and we will need to clean them up and make editing a lot more servicable but for now it is way ahead of where we were with the EMC.
When you started emc2 using the command "scripts/emc configs/demo_step_cl/demo_step_cl.ini" all of the widgets needed to edit ladder are available to you. Move the ladder display to the run you want to edit. This can be a bit tricky. There are little gray lines across the display between rungs.
Let's start by editing the type of estop we want to use for the system. Get to the top run of the ladder display. It should look something like the second row of the estop image above. Press the modify button on the editor and select the horizontal line. Selecting these is not real easy, click near the top of the icon and make certain that a box appears around the one that you really want to use. The horizontal line can be used to turn on a line or off a line. To turn off the line on the top row left, click it and then move down to the second row and click there. You should now have the second row connected and ready to run. Press the okay button and you should see EMC estopped.
In order to use this line you'll need to connect a switch of some sort from parport ground to pin 10. Once you've got that switch in place, you can test all of the different setups.
If you make enough of a mess of ladder that you need to start over, simply close down the emc using either the menu quit or the x on the tkemc display. This closes out ladder but does not save your changes. To save changes you'll need to select save as and find the file demo_step_cl.clp on the right side of that widget, click on it and press save. I'd make a backup of that file before I started editing in case of major screwups. In fact you can use the displays that you saw when you ran the command scripts/emc to make a copy of the entire demo_step_cl system and name it whatever you like. That way you can work with all of the files and see how they fit together to make the system.
In our next edit let's work on changing the timing of the lube rung. To do this you'll need to move that rung into the ladder display and press modify on the edit widget.
Notice that the long arrow near the bottom of the edit widgets has a box around it. That is the thing we need to use to edit parameter values for any ladder element. With that active, you simply point at the element you want to examine or change and you'll see it's parameters show up in the little parameter display window. Here you can see the number of the timer we are looking at in the top row. It is timer 0. The second row shows the time interval to be used. This can be minutes, seconds, or tenths of seconds. The bottom row allows you to set the actual number of time intervals that will be counted.
Now it is time to begin to discover how HAL and Ladder interact to do the things they do. Early in this section we will be depending upon halcmd. Halcmd is a utility that lets us setup and look at connections. In the HAL. The first two or three images below are made using the linux watch command. Watch keeps repeating a command given to it every so often. By combining watch and halcmd we can see what is going on inside the HAL.
Here we can see the connections and the state of each classicladder signal. This is quite a bit like watching the running ladder. See if you can figure out what condition the lube stuff is in, and what else is running.
Here we have a listing of another HAL module. This one is named iocontrol. It can read and write the NML messages that EMC uses to tell IO to turn on or off and what condition (status) all of the IO currently is in. You may be able to pick out several signals that we aren't using or at least you have not seen yet in ladder.
It will probably be easier to read the return from this halcmd if I put the plain text here.
Every 2s: bin/halcmd show pin iocontrol Sun Nov 20 12:10:41 2005
Component Pins: Owner Type Dir Value Name
03 bit -W TRUE iocontrol.0.coolant-flood ==> iocontrol.0.coolant-flood 03 bit -W TRUE iocontrol.0.coolant-mist ==> iocontrol.0.coolant-mist 03 bit R- TRUE iocontrol.0.emc-enable-in <== iocontrol.0.emc-enable-in 03 bit -W TRUE iocontrol.0.lube ==> iocontrol.0.lube 03 bit R- TRUE iocontrol.0.lube_level <== iocontrol.0.lube_level 03 bit -W FALSE iocontrol.0.spindle-brake 03 bit -W FALSE iocontrol.0.spindle-decr-speed 03 bit -W TRUE iocontrol.0.spindle-forward ==> iocontrol.0.spindle-forward 03 bit -W FALSE iocontrol.0.spindle-incr-speed 03 bit -W TRUE iocontrol.0.spindle-on 03 bit -W FALSE iocontrol.0.spindle-reverse ==> iocontrol.0.spindle-reverse 03 float R- 0.00000e+00 iocontrol.0.spindle-speed-in 03 float -W 5.00000e+02 iocontrol.0.spindle-speed-out 03 bit -W FALSE iocontrol.0.tool-change ==> iocontrol.0.tool-change 03 bit R- FALSE iocontrol.0.tool-changed <== iocontrol.0.tool-change 03 u8 -W 0 (00) iocontrol.0.tool-prep-number 03 bit -W FALSE iocontrol.0.tool-prepare ==> iocontrol.0.tool-prepare 03 bit R- FALSE iocontrol.0.tool-prepared <== iocontrol.0.tool-prepare 03 bit -W TRUE iocontrol.0.user-enable-out ==> iocontrol.0.user-enable-out 03 bit -W FALSE iocontrol.0.user-request-enable ==> iocontrol.0.user-request-enable
(more later)